package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.customer.entity.Customer;
import com.ibiaoke.goods.service.PtGoodService;
import com.ibiaoke.order.entity.PtOrder;
import com.ibiaoke.order.service.PtOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class WxPtOrderController extends BaseController {

    @Autowired
    private PtOrderService ptOrderService;

    @Autowired
    private PtGoodService ptGoodService;

    //我的拼团订单查询
    @RequestMapping("/getMyPtOrder")
    @ResponseBody
    public Res getMyPtOrder(Page page) {
        Customer customer = getLoginUser();
        List<PtOrder> ptOrderList = ptOrderService.getMyPtOrder(customer.getCustomerId(), page);
        for (int i = 0; i < ptOrderList.size(); i++) {
            ptOrderList.get(i).setPtGoods(ptGoodService.getGoodsById(ptOrderList.get(i).getGoodId()));
        }
        return Res.create().addResponse("ptOrderList", ptOrderList).addResponse("page", page);
    }

    //根据订单id查询订单
    @RequestMapping("/getMyPtOrderById")
    @ResponseBody
    public Res getMyPtOrderById(Integer orderId) {
        PtOrder ptOrder = ptOrderService.getPtOrderById(orderId);
        ptOrder.setPtGoods(ptGoodService.getGoodsById(ptOrder.getGoodId()));
        return Res.create().addResponse("ptOrder", ptOrder);
    }


    //确认收货
    @RequestMapping("/PtGoodsConfirm")
    @ResponseBody
    public Res PtGoodsConfirm(Integer orderId) {
        ptOrderService.upPtOrderStatus(orderId);
        return Res.create();
    }

    //删除订单
    @RequestMapping("/PtGoodsDelete")
    @ResponseBody
    public Res RemovePtOrder(Integer orderId) {
        ptOrderService.removePtOrder(orderId);
        return Res.create();
    }

    //超时，拼团失败，更改订单状态
    @RequestMapping("/updateOverTimePtOrder")
    @ResponseBody
    public void updateOverTimePtOrder() {
        ptOrderService.updateOverTimePtOrder();
    }

    //取消订单
    @RequestMapping("/updatePtOrderStatusByCancel")
    @ResponseBody
    public Res updatePtOrderStatus(Integer orderId) {
        ptOrderService.updatePtOrderStatusByCancel(orderId);
        return Res.create();
    }

}
